<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>
<script type="text/javascript">
    function searchRecord() {
        var currentForm = document.forms["searchForm"];
        currentForm.elements["searchTO.userId"].value = currentForm.elements["searchTO.userId"].value.trim();
        currentForm.elements["searchTO.userName"].value = currentForm.elements["searchTO.userName"].value.trim();
        submitForm("searchForm", "search.action");
    }

    function addRecord() {
        submitForm("searchForm", "viewAdd.action");
    }

    function updateRecord(recordName) {
        var currentForm = document.forms["searchForm"];
        currentForm.elements["userModel.selectId"].value = recordName;
        submitForm("searchForm", "view.action");
    }    


    function deleteRecord() {
        if (!atLeastOneRecordChecked('searchFormDiv')) {
        	alert('<s:text name="label.select.atleast.one.record"/>');
        } else {
            if (window.confirm('<s:text name="label.confirm.delete"/>')) {
                submitForm("searchForm", "delete.action");
            }
        }
    }   

</script>
<div id='searchFormDiv'>
<s:form name="searchForm" action="" >
    <s:hidden name="userModel.selectId" value=""/>
    <table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
        <tr>
            <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
                <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
            </td>
            <td valign="bottom" class="page_title_bg" width="96%">
                <span class="page_title">
                    <s:text name="label.search.user"/>
                </span>
            </td>
        </tr>
        <tr>
            <td class="subcontent" colspan="2">&nbsp;</td>
        </tr>
    </table>

    <table border="0" align="center" cellpadding="0" cellspacing="0" class="body_content full_width bordered">
        <tr class="odd">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.userId'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left">
                <s:textfield name="searchTO.userId" />
            </td>
        </tr>
        <tr class="even">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.userName'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left">
                <s:textfield name="searchTO.userName" />
            </td>
        </tr>
        <tr class="odd">
            <td class="form_label_padded" width="10%" nowrap><s:text name='label.userRole'/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left">
            <s:select list="roleList" name="searchTO.userRole" listKey="value" listValue="label" headerKey="" headerValue=""/>
            </td>
        </tr>
        <tr class="even">
            <td class="txtData" colspan="6">
                <input type="button" class="button" value="<s:text name='label.search'/>" onclick="searchRecord();">
                <input type="button" class="button" value="<s:text name='label.add'/>" onclick="addRecord();">
                <input type="button" class="button" value="<s:text name='label.delete'/>" onclick="deleteRecord();">
            </td>
        </tr>
        <tr class="odd">
            <td colspan="6">
                <display:table name="helper" form="searchForm" uid="row" action="search.action">
                    <display:column titleKey="label.record.no" width="6%">
                        <s:property
                            value="%{#attr.row_rowNum+(helper.pageNumber-1)*helper.objectsPerPage}" />
                    </display:column>
                    <display:column width="2%">
                        <s:checkbox name="resultList[%{#attr.row_rowNum-1}].selectId"
                            fieldValue="%{#attr.row.userName}" />
                    </display:column>
                    <display:column titleKey="label.userId"  sortable="true" sortProperty="USER_ID" width="23%">
                        <a href="javascript:updateRecord('<s:property value="%{#attr.row.userId}"/>')">
                        <s:property value="%{#attr.row.userId}" /> </a>
                    </display:column>
                    <display:column titleKey="label.userName"  sortable="true" sortProperty="USER_NAME" width="23%">
                        <s:property value="%{#attr.row.userName}" />
                    </display:column>
                    <display:column titleKey="label.userRole"  sortable="true" sortProperty="USER_ROLE" width="23%">
                      <s:if test='#attr.row.userRole=="A"'>
                          <s:text name='label.admin'/>
                      </s:if>
                      <s:if test='#attr.row.userRole=="U"'>
                          <s:text name='label.user'/>
                      </s:if>
                      <s:if test='#attr.row.userRole=="O"'>
                          <s:text name='label.operator'/>
                      </s:if>
                    </display:column>
                    <display:column titleKey="label.createDate"  sortable="true" sortProperty="CREATE_DATE" width="23%">
                        <s:property value="%{#attr.row.createDt}" />
                    </display:column>
                </display:table>
            </td>
        </tr>
    </table>
</s:form>
</div>
